package com.sync.qustion;


/**
 * 调用同一个非静态的同步方法
 * */
public class SimpleMethodNoStatic implements Runnable {

    static SimpleMethodNoStatic simpleMethodNoStatic = new SimpleMethodNoStatic();

    public static void main(String[] args) {
        Thread t1 = new Thread(simpleMethodNoStatic);
        Thread t2 = new Thread(simpleMethodNoStatic);
        t1.start();
        t2.start();
        while(t1.isAlive() || t2.isAlive());
        System.out.println(" finish ");

    }

    @Override
    public void run() {
        method();
    }

    // synchronized 修饰方法的时候默认里面对象是this对象
    public synchronized void method(){
        System.out.println(Thread.currentThread().getName()+"调用同一个非静态的同步方法");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {

        }
        System.out.println(Thread.currentThread().getName()+"运行结束");

    }
}
